import http from '../utils/http'

const apiKey = '49f3b1d8412b7f9f0ce2c9bdb728b23b'
let sign
if (process.env.NODE_ENV === 'production') {
  sign = localStorage.getItem('wish_sign')
} else {
  // sign = '56d94694e8a8d51128d83e9becaf4741'
  // sign = '47b1bd498edf28a5995c1d04ee5b02a4'
  sign = 'abaa6853f328cabb6a6eee23b58b948a'
}

// 获取动态列表
const getSocialList = ({
  page,
  search,
  ruleType
}) => http.post('?s=/wish/wish/getSocialList', {
  api_key: apiKey,
  sign,
  page,
  search,
  rule_type: ruleType
})

// 获取指标类型列表
const getRuleTypeList = () => http.post('?s=/wish/wish/getRuleTypeList', {
  api_key: apiKey,
  sign
})

// 获取指标列表
const getRuleList = () => http.post('?s=/wish/wish/getRuleList', {
  api_key: apiKey,
  sign
})

// 获取指标说明
const getRuleInfo = (ruleId) => http.post('?s=/wish/wish/getRuleInfo', {
  api_key: apiKey,
  sign,
  rule_id: ruleId
})

// 上传图片
let uploadImg
if (process.env.NODE_ENV === 'production') {
  uploadImg = (formData) => http.postFormdata(
    'http://api110.herbplantist.com/sucai/public/index.php/post/post/uploadFile',
    formData)
} else {
  uploadImg = (formData) => http.postFormdata(
    'http://ydnshop.hepulanerp.com/sucai_t/public/index.php/post/post/uploadFile',
    formData)
}

// 获取微信jssdk config
const getJsapiTicket = () => http.post('?s=/wish/wish/getJsapiTicket', {
  api_key: apiKey,
  sign
})

// 获取用户列表(@人用)
const getUserList = ({
  keyword,
  page,
  isDefault
}) => http.post('?s=/wish/wish/getUserList', {
  api_key: apiKey,
  sign,
  search: keyword || '',
  page: page || 1,
  default: isDefault || 0
})

const getIndexInfo = () => http.post('?s=/wish/wish/getIndexInfo', {
  api_key: apiKey,
  sign
})

// 获取我的信息
const getMineInfo = () => http.post('?s=/wish/wish/getMineInfo', {
  api_key: apiKey,
  sign
})

// 获取自己申请的禾分记录
const getUserPointList = ({
  page,
  origin
}) => http.post('?s=/wish/wish/getUserPointList', {
  api_key: apiKey,
  sign,
  page,
  origin // 1为自己申请, 2为总裁办, 3为人力资源
})

// 获取待审批列表
const getProcessList = (page) => http.post('?s=/wish/wish/getProcessList', {
  api_key: apiKey,
  sign,
  page
})

// 获取审批详情
const getProcessInfo = ({
  processId,
  processHeadId
}) => http.post('?s=/wish/wish/getProcessInfo', {
  api_key: apiKey,
  sign,
  process_id: processId,
  process_head_id: processHeadId
})

// 获取任务列表(互动点赞)
const getTaskList = (page) => http.post('?s=/wish/wish/getTaskList', {
  api_key: apiKey,
  sign,
  page
})

// 获取任务详情(互动点赞)
const getTaskInfo = (taskId) => http.post('?s=/wish/wish/getTaskInfo', {
  api_key: apiKey,
  sign,
  task_id: taskId
})

// 添加动态
const addSocial = ({
  ruleId,
  content,
  images,
  location,
  atUserId
}) => http.post('?s=/wish/wish/addSocial', {
  api_key: apiKey,
  sign,
  rule_id: ruleId,
  content,
  images,
  position_place: location,
  notice_userids: atUserId
})

// 新增指标接口
const addRule = ({
  name,
  point,
  ruleType,
  content,
  images
}) => http.post('?s=/wish/wish/addRule', {
  api_key: apiKey,
  sign,
  name,
  point,
  rule_type: ruleType,
  content,
  images
})

// 提交审批结果
const setProcessStatus = ({
  processId,
  result,
  content
}) => http.post('?s=/wish/wish/setProcessStatus', {
  api_key: apiKey,
  sign,
  process_id: processId,
  result, // 1为通过, 2为不通过
  content // 审批意见
})

// 动态点赞
const addSocialPraise = (socialId) => http.post('?s=/wish/wish/addSocialPraise', {
  api_key: apiKey,
  sign,
  social_id: socialId
})

// 取消点赞
const delSocialPraise = (socialId) => http.post('?s=/wish/wish/delSocialPraise', {
  api_key: apiKey,
  sign,
  social_id: socialId
})

// 动态评论及回复评论
const addSocialComment = ({
  socialId,
  content,
  replyCommentId
}) => http.post('?s=/wish/wish/addSocialComment', {
  api_key: apiKey,
  sign,
  social_id: socialId,
  content,
  reply_comment_id: replyCommentId
})

// 删除评论
const delSocialComment = (commentId) => http.post('?s=/wish/wish/delSocialComment', {
  api_key: apiKey,
  sign,
  comment_id: commentId
})

export {
  getSocialList,
  getRuleTypeList,
  getRuleList,
  getRuleInfo,
  uploadImg,
  getUserList,
  getIndexInfo,
  getMineInfo,
  getUserPointList,
  getJsapiTicket,
  getProcessList,
  getProcessInfo,
  getTaskList,
  getTaskInfo,
  addSocial,
  addRule,
  addSocialPraise,
  delSocialPraise,
  addSocialComment,
  delSocialComment,
  setProcessStatus
}
